// import { Redirect, Route, useLocation } from 'react-router-dom'

// import Layout from '@/layout'
// import NotFound from '@/pages/404'
// import storageManage from '@/utils/storageManage'

// function checkAuth() {
//   return storageManage.get('token')
// }
// function renderComponent(path, component, unBagUp) {
//   return unBagUp ? (
//     <Route path={path} component={component} />
//   ) : (
//     <Layout>
//       <Route path={path} component={component} />
//     </Layout>
//   )
// }

// const Guard = ({ Routes }) => {
//   const { pathname } = useLocation()
//   const path = pathname.match(/\/(\w*)/)

//   if (!path || path[0] === '/') {
//     return <Redirect to="/home" />
//   }

//   const targetRouter = Routes.find(router => {
//     return router.path === path[0]
//   })

//   if (!targetRouter) {
//     return <Route path={pathname} component={NotFound} />
//   }

//   const { unAuth, unBagUp, component } = targetRouter

//   if (unAuth) {
//     return renderComponent(pathname, component, unBagUp)
//   }

//   if (checkAuth()) {
//     if (path[0] === '/auth') {
//       return <Redirect to="/home" />
//     }
//     return renderComponent(pathname, component, unBagUp)
//   }

//   return (
//     <Redirect
//       to={{
//         pathname: '/auth/login',
//         state: {
//           origin: pathname,
//         },
//       }}
//     />
//   )
// }
// export default Guard
